package com.fr.cell.core;

import com.fr.base.ColumnRow;
import com.fr.cell.GridColumn;
import com.fr.cell.GridCorner;
import com.fr.cell.GridRow;
import com.fr.cell.GridSelection;
import com.fr.cell.ReportPane;
import com.fr.report.CellElement;
import com.fr.report.Report;
import com.fr.report.TemplateReport;
import java.awt.Rectangle;
import java.awt.event.MouseEvent;
import javax.swing.JScrollBar;
import javax.swing.event.MouseInputAdapter;

public class GridCornerMouseHandler extends MouseInputAdapter
{
  GridCorner gridCorner;

  public GridCornerMouseHandler(GridCorner paramGridCorner)
  {
    this.gridCorner = paramGridCorner;
  }

  public void mouseClicked(MouseEvent paramMouseEvent)
  {
    if (!(this.gridCorner.isEnabled()))
      return;
    ReportPane localReportPane = this.gridCorner.getReportPane();
    doSelectAll();
    localReportPane.getHorizontalScrollBar().setValue(localReportPane.getHorizontalScrollBar().getValue());
    localReportPane.getVerticalScrollBar().setValue(localReportPane.getVerticalScrollBar().getValue());
  }

  private void doSelectAll()
  {
    ReportPane localReportPane = this.gridCorner.getReportPane();
    ColumnRow localColumnRow = GridUtils.getAdjustLastColumnRowOfReportPane(localReportPane);
    GridSelection localGridSelection = localReportPane.getGridSelection();
    localGridSelection.setType(0);
    localGridSelection.setEditBounds(0, 0, 1, 1);
    localGridSelection.setOnlyCellBounds(0, 0, localColumnRow.getColumn(), localColumnRow.getRow());
    dealCellSelection(localReportPane);
    localReportPane.fireGridSelectionChanged();
    GridColumn localGridColumn = this.gridCorner.getReportPane().getGridColumn();
    GridColumnMouseHandler localGridColumnMouseHandler = new GridColumnMouseHandler(localGridColumn);
    localGridColumnMouseHandler.setStartMultiSelectIndex(0);
    localGridColumnMouseHandler.setEndMultiSelectIndex(localColumnRow.getColumn());
    localGridColumn.addMouseListener(localGridColumnMouseHandler);
    localGridColumn.addMouseMotionListener(localGridColumnMouseHandler);
    GridRow localGridRow = this.gridCorner.getReportPane().getGridRow();
    GridRowMouseHandler localGridRowMouseHandler = new GridRowMouseHandler(localGridRow);
    localGridRowMouseHandler.setStartMultiSelectIndex(0);
    localGridRowMouseHandler.setEndMultiSelectIndex(localColumnRow.getRow());
    localGridRow.addMouseListener(localGridRowMouseHandler);
    localGridRow.addMouseMotionListener(localGridRowMouseHandler);
  }

  public void mouseMoved(MouseEvent paramMouseEvent)
  {
    if (!(this.gridCorner.isEnabled()))
      return;
    this.gridCorner.setCursor(GUIConstants.CellDefaultCursor);
  }

  private void dealCellSelection(ReportPane paramReportPane)
  {
    TemplateReport localTemplateReport = paramReportPane.getEditingReport();
    GridSelection localGridSelection = paramReportPane.getGridSelection();
    int i = localGridSelection.getType();
    if (i == 1)
      return;
    Rectangle localRectangle = localGridSelection.getEditRectangle();
    int j = localRectangle.x;
    int k = localRectangle.y;
    int l = localRectangle.width;
    int i1 = localRectangle.height;
    CellElement localCellElement = localTemplateReport.getCellElement(j, k);
    if (localCellElement != null)
    {
      l = localCellElement.getColumnSpan();
      i1 = localCellElement.getRowSpan();
    }
    localRectangle.width = l;
    localRectangle.height = i1;
  }
}